package cn.tedu.tmall.front.mall.startup;

import cn.tedu.tmall.front.mall.service.ICategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 缓存预热（预加载）
 * 类别树加载器，用于从数据库获取分类并存储到redis
 */
@Slf4j
@Component
public class CategoryLoader implements ApplicationRunner {
    @Autowired
    private ICategoryService categoryService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.debug("ApplicationRunner:开始加载分类数据到redis");
        //todo 业务流程
        //类别树用什么redis数据类型保存？Set
        categoryService.initCategory();
        log.debug("ApplicationRunner:加载分类数据到redis成功！");
    }

    //todo 可见性
    private volatile Integer abc = 1;
}
